<div style="display:none" id="more-recipe-detail-vn">
	<div class="form-group row">
		<hr>
        <button type="button" class="btn btn-danger btn-xs delete-detail">Delete Group</button><br><br>
		<div class="recipe-detail">
			<div class="form-group row">
				<div class="col-sm-6">
					<input type="text" maxlength="100" placeholder="element name" name="RecipeDetail[name][]" value="" class="form-control">
				</div>
				<div class="col-sm-6">
					<input type="text" maxlength="100" placeholder="element name en" name="RecipeDetail[name_en][]" value="" class="form-control">
				</div>
			</div>
			<?php echo $this->element('AdminRecipes/detail_default');?>
		</div>
		<div align="right"><i class="glyphicon glyphicon-plus-sign add-recipe1" rel="num" style="cursor:pointer"></i> Add element</div>
	</div>
</div>
<div style="display:none" id="step-detail-vn"><?php echo $this->element('AdminRecipes/detail_default');?></div>

<script type="text/javascript">
$(document).ready(function () {
	$("#elements-recipe-vn").on("click", ".add-recipe1", function () { 
		//var elementCount = $('#elements-recipe-vn').find('.delete-detail').length;
		element = $(this).attr('rel');
		var step = $('#step-detail-vn').html()
		var html = step.replace(/num/g, element); 
		$(this).parent().prev().append(html);
	});

	$("#elements-recipe-vn").on("click", ".add-recipe", function () { 
		var step = $('#step-detail-vn').html()
		var html = step.replace(/num/g, 0); 
		$(this).parent().prev().append(html);
	});
	
	$(".control-group").on("click", ".delete-step", function(){
		var _this = $(this);
		var id = $(this).attr('rel');
		$.ajax({
			url: '/admin/recipes/deleteStep',
			data: {'id': id},
			type: 'post',
			success: function(response) {
				if(response) _this.parent().parent().remove();
			}
		});
	});
    
    $(".control-group").on("click", ".delete-detail", function(){
		var _this = $(this);
		var id = $(this).attr('rel');
		$.ajax({
			url: '/admin/recipes/deleteDetail',
			data: {'id': id},
			type: 'post',
			success: function(response) {
				if(response) _this.parent().remove();
			}
		});
	});
	
	$("#more-recipe-vn").click(function () { 
		var elementCount = $('#elements-recipe-vn').find('.delete-detail').length;
		var element = $('#more-recipe-detail-vn').html()
		var html = element.replace(/num/g, elementCount + 1); 
		$('#elements-recipe-vn').append(html);
	});
});
</script>